package com.baizhi.syh.service;

import com.baizhi.syh.DAO.UserMapper;
import com.baizhi.syh.VO.PageVO;
import com.baizhi.syh.VO.ResultVO;
import com.baizhi.syh.VO.UserResultVO;
import com.baizhi.syh.entity.User;
import com.baizhi.syh.entity.UserExample;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class UserServiceImpl implements UserService{

    @Autowired
    private UserMapper userMapper;

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public UserResultVO selectUserPage(PageVO pageVO) {
        //相当于是一个条件，没有条件对所有数据进行分页
        UserExample example = new UserExample();
        //分页查询： 参数：忽略几条,获取几条数据
        RowBounds rowBounds = new RowBounds((pageVO.getPage()-1)*pageVO.getPageSize(),pageVO.getPageSize());

        UserResultVO userResultVO = new UserResultVO();
        userResultVO.setRows(userMapper.selectByExampleAndRowBounds(example,rowBounds));
        userResultVO.setPage(pageVO.getPage());
        userResultVO.setTotal(userMapper.selectCount(new User()));
        return userResultVO;
    }
}
